package com.xzcedu.tankgame6;

import javax.swing.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Scanner;

/**
 * @author 徐州城
 * @version 1.0
 */
public class XzcTankGame06 extends JFrame {

    //定义MyPanel
    MyPanel mp = null;

    static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {

        XzcTankGame06 xzc = new XzcTankGame06();
    }

    public XzcTankGame06(){
        System.out.print("请选择 1: 新游戏   2: 继续上局游戏");
        String key = scanner.next();
        mp = new MyPanel(key);
        //将mp 放入到Thread 并启动线程
        new Thread(mp).start();
        
        this.add(mp);//把面板(游戏的绘图区域)
        this.setSize(1300,800);
        this.addKeyListener(mp);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);

        //在JFrame 中增加相应关闭窗口的处理
        this.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.out.println("监听到关闭窗口..");
                Recorder.keepRecord();
                System.exit(0);
            }
        });
    }
}
